﻿cmake_minimum_required(VERSION 3.10)

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 添加示例程序
add_executable(units_example example1.cpp)

# 静态库定义
if(NOT BUILD_SHARED_LIBS)
    target_compile_definitions(units_example PRIVATE
        UNITS_STATIC_DEFINE
        LIBCONFIG_STATIC
        LIBCONFIGXX_STATIC
    )
endif()

# 链接依赖库
target_link_libraries(units_example PRIVATE
    libunits::libunits
)

# 设置输出目录
set_target_properties(units_example PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
    OUTPUT_NAME "units_example"
)

# 安装示例（可选）
install(TARGETS units_example
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/examples
)

# 确保构建顺序
add_dependencies(units_example libunits)

# Windows符号处理
if(WIN32)
    target_link_options(units_example PRIVATE
        "-Wl,--allow-multiple-definition"
    )
endif()
